import { defineStore } from 'pinia'
import { ApiRes, BannerItem, Brand, CategoryGoods, HotGoods, HomeProduct, HomeSpecial } from "@/types/data"
import request from '@/utils/request'

export default defineStore('home', {
  state: () => ({
    bannerList: [] as BannerItem[],
    newGoodsList: [] as CategoryGoods[],
    hotGoodsList: [] as HotGoods[],
    brandList: [] as Brand[],
    productList: [] as HomeProduct[],
    specialList: [] as HomeSpecial[],
  }),
  actions: {
    async getBannerList() {
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      this.bannerList = res.data.result
    },
    async getNewGoodsList() {
      const res = await request.get<ApiRes<CategoryGoods[]>>('/home/new')
      this.newGoodsList = res.data.result
    },
    async getHotGoodsList() {
      const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
      this.hotGoodsList = res.data.result
    },
    async getBrandList() {
      const res = await request.get<ApiRes<Brand[]>>('/home/brand')
      this.brandList = res.data.result
    },
    async getProductList() {
      const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
      this.productList = res.data.result
    },
    async getSpecialList() {
      const res = await request.get<ApiRes<HomeSpecial[]>>('/home/special')
      this.specialList = res.data.result
    },
  }
})